package com.ecarx.camera.worker.event;

import androidx.annotation.IntDef;

import com.ecarx.camera.constant.Constants;
import com.jeremyliao.liveeventbus.core.LiveEvent;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Dvr相关Event
 */
public class DvrEvent {

    /**
     * Dvr拍照结果状态
     */
    public static class CaptureResultEvent implements LiveEvent {
        public boolean success;

        public CaptureResultEvent(boolean success) {
            this.success = success;
        }
    }

    /**
     * Dvr录像开始状态
     */
    public static class RecordingStartedEvent implements LiveEvent {
        public @Constants.DvrRecordingType int recordingType;

        public RecordingStartedEvent(int recordingType) {
            this.recordingType = recordingType;
        }
    }

    /**
     * Dvr录像结束状态
     */
    public static class RecordingEndedEvent implements LiveEvent {
        public @Constants.DvrRecordingType int recordingType;
        public boolean success;

        public RecordingEndedEvent(int recordingType, boolean success) {
            this.recordingType = recordingType;
            this.success = success;
        }
    }

    /**
     * Dvr错误状态
     */
    public static class DvrStateErrorEvent implements LiveEvent {
        public boolean isErrorState;
        public @DvrErrorState int dvrErrorState;

        public DvrStateErrorEvent(boolean isErrorState) {
            this.isErrorState = isErrorState;
        }

        public DvrStateErrorEvent(boolean isErrorState, @DvrErrorState int dvrErrorState) {
            this.isErrorState = isErrorState;
            this.dvrErrorState = dvrErrorState;
        }
    }

    /**
     * Dvr错误状态定义
     */
    @Documented
    @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
    @IntDef(value = {
            DvrErrorState.DVR_STATE_CAMERA_CONNECTION_LOST,
            DvrErrorState.DVR_STATE_VIDEO_RECORD_FAILURE,
            DvrErrorState.DVR_STATE_NETWORK_ABNORMAL,
            DvrErrorState.DVR_STATE_ACCELERATION_SENSOR_ABNORMAL,
            DvrErrorState.DVR_STATE_MEMORY_READ_ERROR,
            DvrErrorState.DVR_STATE_MEMORY_WRITE_ERROR,
            DvrErrorState.DVR_STATE_SYSTEM_ERROR,
            DvrErrorState.DVR_STATE_360_VIEWS_MODULE_ERROR,
            DvrErrorState.DVR_STATE_OVER_HEAT,
            DvrErrorState.DVR_STATE_RESOURCE_OCCUPIED,
            DvrErrorState.SDCARD_STATUS_POOR_WRITE_PERFORMANCE,
            DvrErrorState.DVR_STATE_VOLTAGE_ABNORMAL,
            DvrErrorState.DVR_STATE_UNKNOWN_ERROR,
            DvrErrorState.DVR_STATE_EMMC_STATUS_ERROR,
            DvrErrorState.DVR_STATE_NO_ERROR
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface DvrErrorState {
        /**
         * Camera connection lost<br>
         * 视频采集系统故障
         */
        int DVR_STATE_CAMERA_CONNECTION_LOST = 0x05;
        /**
         * Video recording failure<br>
         * 录像失败,无法进行录像和拍照,可以进行回放
         */
        int DVR_STATE_VIDEO_RECORD_FAILURE = 0x06;
        /**
         * Network abnormal<br>
         * 行车记录仪出现异常,部分功能受限
         */
        int DVR_STATE_NETWORK_ABNORMAL = 0x07;
        /**
         * Acceleration sensor abnormal<br>
         * 行车记录仪出现异常,部分功能受限
         */
        int DVR_STATE_ACCELERATION_SENSOR_ABNORMAL = 0x08;
        /**
         * memory read error<br>
         * 行车记录仪系统错误,无法正常工作
         */
        int DVR_STATE_MEMORY_READ_ERROR = 0x09;
        /**
         * memery write error<br>
         * 行车记录仪系统错误,无法正常工作
         */
        int DVR_STATE_MEMORY_WRITE_ERROR = 0x0A;
        /**
         * system error<br>
         * 行车记录仪系统错误,无法正常工作
         */
        int DVR_STATE_SYSTEM_ERROR = 0x0B;
        /**
         * 360 views module error<br>
         * 全景影像错误
         */
        int DVR_STATE_360_VIEWS_MODULE_ERROR = 0x0C;
        /**
         * over heat<br>
         * 行车记录仪过热,无法正常工作,散热完毕后将重启
         */
        int DVR_STATE_OVER_HEAT = 0x0D;
        /**
         * resource occupied<br>
         * 行车记录仪资源被占用,暂时无法操作
         */
        int DVR_STATE_RESOURCE_OCCUPIED = 0x0E;
        /**
         * Poor TF card writing performance<br>
         * 行车记录TF卡写速变慢,建议格式化卡片恢复速度
         */
        int SDCARD_STATUS_POOR_WRITE_PERFORMANCE = 0x0F;
        /**
         * voltage abnormal<br>
         * 行车记录仪电压异常,无法正常工作,电压恢复正常范围后将重启
         */
        int DVR_STATE_VOLTAGE_ABNORMAL = 0x10;
        /**
         * Unknown Error<br>
         * 未知错误
         */
        int DVR_STATE_UNKNOWN_ERROR = 0x11;
        /**
         * dvr emmc code: dvr emmc error <br>
         * dvr emmc code : 故障
         */
        int DVR_STATE_EMMC_STATUS_ERROR = 0x12;
        /**
         * No Error <br>
         * 无错误
         */
        int DVR_STATE_NO_ERROR = 0x13;
    }
}
